#include "stm32f10x.h"                  // Device header
#include "I2C.h"
#include "I2C_Soft.h"
#include "Delay.h"
#define SHT40_I2C_Addr (0x44<<1)
float Temperature = 20,Humidity = 50;
void SHT40_Init(void) {
	//I2C_Periph_Init();
	I2C_Soft_Init();
}
void SHT40_Measure(void) {
	uint8_t writeData[1] = {0xfd};
	uint8_t readData[6] = {0};
	//I2C_Master_Write(SHT40_I2C_Addr,(uint8_t *)writeData,1);
	I2C_Soft_Master_Write(SHT40_I2C_Addr,(uint8_t *)writeData,1);
	Delay_ms(10);
	//I2C_Master_Read(SHT40_I2C_Addr,(uint8_t *)readData,6);
	I2C_Soft_Master_Read(SHT40_I2C_Addr,(uint8_t *)readData,6);
	Temperature = (1.0*175*(readData[0]*256+readData[1]))/65535.0-45;
	Humidity = (1.0*125*(readData[3]*256+readData[4]))/65535.0-6.0;
}
float SHT40_GetTemperature(void) {
	return Temperature;
}
float SHT40_GetHumidity(void) {
	return Humidity;
}
